﻿<?php
defined("_VALID_ACCESS") || die('Direct access forbidden');
class SCTV_MaterialInstall extends ModuleInstall {
 
    public function install() { // Here you can place the installation process for the module
 
	Base_ThemeCommon::install_default_theme($this->get_type());
	
	$fields = array(
		array('name'=>_M('Material Code'), 'type'=>'text', 'param'=>32, 'required'=>true, 'visible'=>true),
		array('name'=>_M('Material Name'), 'type'=>'text', 'param'=>128, 'required'=>true, 'visible'=>true),
		array('name'=>_M('Material Unit'), 'type'=>'text', 'param'=>32, 'required'=>true, 'visible'=>true),
		array('name'=>_M('Current Price'), 'type'=>'calculated', 'param'=>Utils_RecordBrowserCommon::actual_db_type('integer'), 'required'=>true, 'visible'=>true, 'display_callback'=>array('SCTV_MaterialCommon', 'display_current_price')),
		array('name'=>_M('Material Free'), 'type'=>'checkbox', 'required'=>true, 'visible'=>true),
		array('name'=>_M('IsTVBox'), 'type'=>'checkbox', 'required'=>true, 'visible'=>true),
		array('name'=>_M('Ordinary'), 'type'=>'checkbox', 'required'=>true, 'visible'=>true),
		array('name'=>_M('Ordinal'), 'type'=>'integer', 'required'=>false, 'visible'=>true)		
	);
	
	Utils_RecordBrowserCommon::install_new_recordset('SCTV_Material', $fields);
	Utils_RecordBrowserCommon::set_caption('SCTV_Material', _M('Material'));
	Utils_RecordBrowserCommon::add_default_access('SCTV_Material');
	
	$fields = array(
			array('name'=>_M('Material'), 'type'=>'select', 'param'=>array('SCTV_Material'=>'Material Code|Material Name'), 'required'=>true, 'visible'=>false),					
			array('name'=>_M('From Date'), 'type'=>'date', 'required'=>true, 'visible'=>true),
			array('name'=>_M('Price'), 'type'=>'integer', 'required'=>true, 'visible'=>true, 'display_callback'=>array('SCTV_MaterialCommon', 'display_price')),																						
			array('name'=>_M('Note'), 'type'=>'text', 'param'=>256, 'required'=>false, 'visible'=>true)			
		);
	
	Utils_RecordBrowserCommon::install_new_recordset('SCTV_MaterialPrice', $fields);
	Utils_RecordBrowserCommon::set_caption('SCTV_MaterialPrice', _M('Material Price'));
	Utils_RecordBrowserCommon::add_default_access('SCTV_MaterialPrice');
	
	Utils_RecordBrowserCommon::new_addon('SCTV_Material', 'SCTV_Material', 'material_price_addon', _M('Price'));
	
    return true; // Return true on success and false on failure
    }
 
    public function uninstall() { // Here you can place uninstallation process for the module
		Base_ThemeCommon::uninstall_default_theme($this->get_type());
		Utils_RecordBrowserCommon::uninstall_recordset('SCTV_MaterialPrice');
		Utils_RecordBrowserCommon::uninstall_recordset('SCTV_Material');
				
		return true;
    }
 
    public function info() { // Returns basic information about the module which will be available in the epesi Main Setup
 
        return array( 'Author'=>'Pham Huu Le Quoc Phuc',
            'License'=>'SCTV',
                     'Description'=>'Material');
 
    }
 
    public function simple_setup() { // Indicates if this module should be visible on the module list in Main Setup's simple view
 
        return array('package' => __('Material'), 'version'=>'1.0'); // - now the module will be visible as "HelloWorld" in simple_view
 
    }
 
    public function requires($v) { // Returns list of modules and their versions, that are required to run this module
 
        return array();
 
    }
 
    public function version() { // Return version name of the module
 
        return array('1.0');
 
    }
}
 
?>